<template>
  <a :class="className" @click="handleDownload">{{buttonText}}</a>
</template>
<script>
export default {
  name: 'AnnexDownloadButton',
  props: {
    value: { type: String, default: '' },
    className: {
      type: String,
      default: 'download-btn'
    },
    buttonText: {
      type: String,
      default: '下载附件'
    },
    buttonType: {
      type: String,
      default: 'primary'
    },
    fileName: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      downloading: false,
      downloadLink: ''
    }
  },
  watch: {
    value (val) {
      this.downloadLink = val
    },
  },
  methods: {
    handleDownload () {
      if (!this.value) {
        return
      }
      const fileName = this.value.split('/').pop() // this.fileName || this.value.split('/').pop()
      const url = `${this.exportBaseURL}/srm-admin/annex/download?fullPath=${this.value}&fileName=${fileName}`

      window.open(url, '_blank')
    },
  },
}
</script>
<style scoped>
.download-btn {
  font-size: 12px;
}
</style>
